package presentation;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.border.LineBorder;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class ModifyMsgForm extends javax.swing.JDialog {

	private static final long serialVersionUID = -124101018674196869L;
	private JTextField subject;
	private JTextArea MsgBody;
	private JButton cancelButton;
	private JButton OkButton;
	private JLabel msgBodyLabel;
	private JLabel bodyLabel;
	private JLabel SubjectLabel;

	public ModifyMsgForm(JFrame frame, String oldSub, String oldBody) {
		super(frame);
		initGUI();
		this.subject.setText(oldSub);
		this.MsgBody.setText(oldBody);
	}

	private void initGUI() {
		try {
			GridBagLayout thisLayout = new GridBagLayout();
			thisLayout.rowWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.1};
			thisLayout.rowHeights = new int[] {55, 26, 23, 30, 159, 37, 34, 20};
			thisLayout.columnWeights = new double[] {0.0, 0.0, 0.1, 0.0, 0.0, 0.0, 0.1};
			thisLayout.columnWidths = new int[] {36, 55, 7, 90, 81, 106, 20};
			getContentPane().setLayout(thisLayout);
			{
				subject = new JTextField();
				getContentPane().add(subject, new GridBagConstraints(2, 1, 4, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
				subject.setBorder(new LineBorder(new java.awt.Color(0,0,0), 1, false));
			}
			{
				SubjectLabel = new JLabel();
				getContentPane().add(SubjectLabel, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
				SubjectLabel.setText("Subject");
				SubjectLabel.setFont(new java.awt.Font("Tahoma",1,16));
			}
			{
				MsgBody = new JTextArea();
				getContentPane().add(MsgBody, new GridBagConstraints(2, 3, 5, 2, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
				MsgBody.setBorder(new LineBorder(new java.awt.Color(0,0,0), 1, false));
			}
			{
				msgBodyLabel = new JLabel();
				getContentPane().add(MsgBody, new GridBagConstraints(2, 3, 4, 2, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
				MsgBody.setPreferredSize(new java.awt.Dimension(391, 189));
				{
					bodyLabel = new JLabel();
					getContentPane().add(getBodyLabel(), new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
					bodyLabel.setText("Text");
					bodyLabel.setFont(new java.awt.Font("Tahoma",1,16));
				}
				msgBodyLabel.setText("Text");
				msgBodyLabel.setFont(new java.awt.Font("Tahoma",1,16));
			}
			{
				OkButton = new JButton();
				getContentPane().add(OkButton, new GridBagConstraints(2, 6, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
				OkButton.setText("Save");
				OkButton.setFont(new java.awt.Font("Tahoma",1,16));
				OkButton.addActionListener(new ActionListener(){
					public void actionPerformed(ActionEvent e) {
						okHandler();
					}

				});
			}
			{
				cancelButton = new JButton();
				getContentPane().add(cancelButton, new GridBagConstraints(4, 6, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
				cancelButton.setText("Cancel");
				cancelButton.setFont(new java.awt.Font("Tahoma",1,16));
				cancelButton.addActionListener(new ActionListener(){
					public void actionPerformed(ActionEvent e) {
						cancelHandler();
					}

				});
			}
			pack();
			setVisible(true);
			this.setTitle("Modify A Message");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private void okHandler() {
		String newSubj = this.subject.getText();
		String newBody = MsgBody.getText();
		if(newSubj.length()>0 && newBody.length()>0 ){
			WsepGUI tGUI = (WsepGUI)this.getParent();
			tGUI.modifyMessage(this, newSubj, newBody);
			this.close();
		}
		else{
			JOptionPane.showMessageDialog(this, "Missing subject or text", "Error!", JOptionPane.ERROR_MESSAGE);
		}
	}

	private void cancelHandler() {
		((WsepGUI)this.getParent()).setFather();
		this.close();
	}

	/**
	 * enable my owner (meaning - the JFrame that is passed to the Constructor)
	 * and close myself
	 */
	private void close() {
		this.getParent().setEnabled(true);
		this.dispose();
	}


	public JTextArea getMsgBody() {
		return MsgBody;
	}

	public JButton getOkButton() {
		return OkButton;
	}

	public JLabel getBodyLabel() {
		return bodyLabel;
	}

}